<template>
    <div class="header">
      <div class="title">
        编辑管理员信息
      </div>
        <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" label-width="100px" label-position="left" class="demo-ruleForm"
            :size="formSize" status-icon>
            <el-form-item label="用户名" prop="name">
                <el-input v-model="ruleForm.name" placeholder="请输入用户名" />
            </el-form-item>

            <el-form-item label="账号" prop="number">
                <el-input v-model="ruleForm.name" placeholder="请输入账号" />
            </el-form-item>

            <el-form-item label="选择角色" prop="role">
                <el-select v-model="ruleForm.role" placeholder="请选择角色">
                    <el-option label="超级管理员" value="0" />
                    <el-option label="管理员" value="1" />
                    <el-option label="普通员工" value="2" />
                </el-select>
            </el-form-item>

            <el-form-item label="手机号码">
                <el-input v-model="ruleForm.phone" />
            </el-form-item>

            <el-form-item label="密码" prop="password">
                <el-input v-model="ruleForm.password" placeholder="请输入密码" />
            </el-form-item>

            <el-form-item label="状态" prop="enable">
                <el-switch v-model="ruleForm.enable" />
            </el-form-item>

            <el-form-item style="margin-top: 45px;">
                <el-button type="primary" @click="submitForm(ruleFormRef)">保存</el-button>
                <el-button @click="resetForm(ruleFormRef)">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
  
<script lang="ts" setup>
import { reactive, ref } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'

const formSize = ref('default')
const ruleFormRef = ref<FormInstance>()
const ruleForm = reactive({
    name: '',
    number: '',
    count: '',
    role: '',
    enable: true,
    phone: '',
    password: ''
})

const rules = reactive<FormRules>({
    name: [
        { required: true, message: 'Please input Activity name', trigger: 'blur' },
        { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
    ],
    number: [
        { required: true, message: 'Please input Activity name', trigger: 'blur' },
        { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
    ],
    password: [
        { required: true, message: 'Please input Activity name', trigger: 'blur' },
        { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
    ],
    role: [
        {
            required: true,
            message: 'Please select Activity zone',
            trigger: 'change',
        },
    ],
})

const submitForm = async (formEl: FormInstance | undefined) => {
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            console.log('submit!')
        } else {
            console.log('error submit!', fields)
        }
    })
}

const resetForm = (formEl: FormInstance | undefined) => {
    if (!formEl) return
    formEl.resetFields()
}

</script>
  
<style>
.header {
    background-color: white;
    padding: 40px 50px;
    border-radius: 10px;
    box-sizing: border-box;
    height: 100%;
}

.el-input {
    width: 350px !important;
}

.title{
    font-weight: 500;
    font-size: 16px;
    color: rgba(0,110,255,1);
    margin-bottom: 30px;
}
</style>